package com.betty.cscams.common.exception;


import com.betty.cscams.common.http.HttpResult;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;



/**
 * 全局异常处理器
 *
 */
@RestControllerAdvice
public class GlobalExceptionHandler
{
    private static final Logger log = LoggerFactory.getLogger(GlobalExceptionHandler.class);

    /**
     * 基础异常
     */
    @ExceptionHandler(AuthCscaException.class)
    public HttpResult authCscaException(AuthCscaException e)
    {
        return HttpResult.error(401,e.getMessage());
    }

    /**
     * 业务异常
     */
    @ExceptionHandler(CscaException.class)
    public HttpResult cscaException(CscaException e)
    {
            return HttpResult.error(e.getMessage());
    }


    @ExceptionHandler(RuntimeException.class)
    public HttpResult handleException(Exception e)
    {
        log.error(e.getMessage(), e);
        return HttpResult.error(e.getMessage());
    }

}
